<template>
  <div class="right-home">
    <div class="right-home-top">
      <div class="sele">
        <el-select v-model="values" @change="valueChange" filterable placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.stationId"
            :label="item.stationName"
            :value="item.stationId"
            
          ></el-option>
        </el-select>
      </div>
      <div class="btn">
        <el-button @click="added" type="primary">新建</el-button>
      </div>
    </div>
    <div class="right-home-foot" v-if="isShow">
      <div
        class="attribute-box"
        v-for="(item, index) in formData"
        :key="index"
        @dblclick="shishiClick(index,item.areaId)"
      >
        <div>
          <div :title="item.name" class="text">{{ item.areaName }}</div>
          <div @click="open(index,item.areaId)" class="switch">
            <i class="el-icon-delete"></i>
            <div :class="item.slide === true ? 'slide' : 'close-slide'"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="right-home-foot " v-else>
      <div class="zwsj">暂无数据</div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue ,Watch} from "vue-property-decorator";
import { ParameterManagementModule } from "@/store/modules/ParameterManagement";

@Component
export default class extends Vue {
  public isShow=false
  public options: object = [
  ];
  public values: string = ''
  //开关按钮
  public slide: boolean = false;

  public input: string | number = "";
  public Inputbox: boolean = false;
  public formData: Array<any> = [];
  get treeSbIds() {
    return ParameterManagementModule.treeSbIdName.id;
  }
  get treeSbIdsName() {
    return ParameterManagementModule.treeSbIdName.name;
  }
   get treeSbSsdsId() {
    //  console.log(ParameterManagementModule.treeSbIdName.ssdsId);
     
    return ParameterManagementModule.treeSbIdName.ssdsId;
  }
 
  //删除按钮提示框
  open(index: number, id: any) {
    var _this = this;
    this.formData[index].slide = true;
    this.$confirm("此操作将永久删除该文件, 是否继续?", "删除", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    })
      .then(() => {
        (this as any).$services
          .deleteQy({ data: { id: id }, method: "delete" })
          .then((result: any) => {
            // console.log(result);
            if (result.code == 200) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
            }
            _this.init();
          })
          .catch((err: object) => {
            console.log(err);
          });
      })
      .catch(() => {
        _this.formData[index].slide = false;
        this.$message({
          type: "info",
          message: "已取消删除",
        });
      });
  }
  //新增
  added() {
   var  _this=this
    this.$prompt("请输入维护区域名称", "新增", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      // inputPattern: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
      inputErrorMessage: "维护区域名称格式不正确",
    })
      .then((value) => {
        var from = {
          bz: "",
          code: "",
          haschil: "",
          lrsj: "",
          menuurl: "",
          name: "",
          objId: "",
          pid: "",
          qyjb: "",
          ssbdzId: _this.treeSbIds,
          ssbdzMc: _this.treeSbIdsName,
        };
        from.name = (value as any).value;
        (this as any).$services
          .insertQy({ data: from, method: "post" })
          .then((result: any) => {
            // console.log(result);
            if (result.code == 200) {
              this.$message({
                type: "success",
                message: result.message,
              });
              this.init();
            }
          })
          .catch((err: object) => {
            console.log(err);
          });

        // this.formData.push({ name: (value as any).value, slide: false });
      })
      .catch(() => {
        this.$message({
          type: "info",
          message: "取消输入",
        });
      });
  }
  shishiClick(index: number,id:any) {
    this.formData[index].Inputbox = true;
  var _this=this
    this.$prompt("请输入维护区域名称", "修改", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      inputErrorMessage: "维护区域名称格式不正确",
    })
      .then((value) => {
        this.formData[index].name = (value as any).value;
        var from={areaname:'',id:''};
          from.areaname=(value as any).value;
          from.id=id;
        (this as any).$services
              .updateQy({ data:from, method: "post",postparams:true})
              .then((result: any) => {
                // console.log(result);
                 if (result.code == 200) {
              this.$message({
                type: "success",
                message: result.message,
              });
              _this.init();
            }
              })
              .catch((err: object) => {
                console.log(err);
              });
        

      })
      .catch(() => {
        this.$message({
          type: "info",
          message: "取消输入",
        });
      });
  }
  init() {
    // console.log("RRRR");
    var from = {
      station: this.BDZListId,
    };
    // console.log(from);
    
    (this as any).$services
      .getAreaByStation({ data: from })
      .then((result: any) => {
        // console.log(result);
        this.formData = result.data;
        if (this.formData.length > 0) {
          this.isShow=true
        }else{
          this.isShow=false
        }
      })
      .catch((err: object) => {
        console.log(err);
      });

     
      
  }
  // 搜索下拉框
  StationList(){
 (this as any).$services
            .getStationList({ data: {'ssds':this.treeSbSsdsId} })
            .then((result: any) => {
              // console.log(result);
              this.options=result.data
            })
            .catch((err: object) => {
              console.log(err);
            });
  }
   //下拉查询
  valueChange(val){
    console.log(val);
    this.BDZListId=val
    this.init()
  }
  mounted() {
    this.init();
    this.StationList()
    this.values=this.treeSbIdsName
    
  }
    // 监听变电站Id
    BDZListId=''
  @Watch("treeSbIds",{immediate: true,deep: true })
  private setSocketSubscribe(newData, oldData) {
    this.BDZListId=newData;
    this.init()
    this.values=this.treeSbIdsName

    console.log(this.BDZListId);
    // this.subscribeAll(newData);
  }
}
</script>

<style lang="scss" scoped>
.right-home {
  width: 100%;
  height: 100%;
  .right-home-top {
    width: 100%;
    height: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    .sele {
      margin-right: 0.3rem;
    }
    .btn {
      margin-right: 0.4rem;
      .el-button--primary {
        font-size: 0.18rem;
      }
    }
  }
  .right-home-foot {
    width: 100%;
    height: calc(100% - 0.9rem);
    overflow: auto;
    box-sizing: border-box;
    .attribute-box {
      width: 3rem;
      height: 1.79rem;
      display: inline-block;
      margin: 0.2rem 0.31rem;
      background: url(../../../../../../assets/img/ParameterManagement/men.png);
      background-size: 100% 100%;
      box-shadow: 0px 0.05rem 0.1rem #08153f;
      position: relative;
      > div {
        width: 52%;
        height: 70%;
        position: absolute;
        top: 50%;
        right: 0.02rem;
        transform: translateY(-50%);
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        .text {
          font-size: 0.24rem;
          width: 100%;
          cursor: pointer;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .switch {
          display: inline-block;
          width: 80px;
          height: 26px;
          border-radius: 13px;
          border: 1px solid rgba(171, 179, 200, 0.5);
          position: relative;
          cursor: pointer;
          > div {
            width: 54%;
            height: 100%;
            position: absolute;
            left: 0;
            top: 0;
            border-radius: 13px;
            background: linear-gradient(
              360deg,
              rgba(20, 123, 252, 1) 0%,
              rgba(12, 157, 254, 1) 40%,
              rgba(3, 191, 255, 1) 100%
            );
            z-index: 9;
          }
          .slide {
            transition: all 0.5s;
            width: 100%;
          }
          .close-slide {
            transition: all 0.5s;
            width: 54%;
          }
          i {
            position: absolute;
            right: 10px;
            top: 3px;
            font-size: 18px;
            color: red;
          }
        }
      }
    }
    .zwsj{
      // text-align: center;
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}
</style>